//
//  HCCustomLoad.m
//  YOGProj
//
//  Created by liyun on 14-7-22.
//  Copyright (c) 2014年 qkong. All rights reserved.
//

#import "HCCustomLoad.h"
#import "HCMacroDefinition.h"

@implementation HCCustomLoad

- (id)initWithFrame:(CGRect)frame loadType:(int)type msg:(NSString *)msg
{
    self = [super initWithFrame:frame];
    if (self) {

        if(type == 0)
        {
            self.backgroundColor      = [UIColor colorWithRed:1/255.0 green:1/255.0 blue:1/255.0 alpha:0.4f];
            UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            indicator.frame = CGRectMake(26, 18, 32, 32);
            
            UIImageView *indicatorBackView = [[UIImageView alloc] initWithFrame:CGRectMake(118, (self.frame.size.height-68)/2, 84, 68)];
            indicatorBackView.userInteractionEnabled = YES;
            indicatorBackView.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCjuhua_back" ofType:@"png"]];
            [indicatorBackView addSubview:indicator];
            
            [self  addSubview:indicatorBackView];
            [indicator      startAnimating];
        }
        else
        {
            self.backgroundColor = [UIColor clearColor];
            int line = msg.length>20?2:1;
            UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 260, 30+26*(line-1))];
            image.backgroundColor = [UIColor blackColor];
            image.alpha = 0.7;
            [self addSubview:image];
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 7, 260, 19*line)];
            label.text = msg;
            label.numberOfLines = line;
            label.backgroundColor = [UIColor clearColor];
            label.textAlignment = NSTextAlignmentCenter;
            label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
            label.textColor = [UIColor whiteColor];
            [self addSubview:label];
            [self performSelector:@selector(cancelAll) withObject:nil afterDelay:2];
        }
    }
    return self;
}

- (void)cancelAll
{
    if(self)
        [self removeFromSuperview];
}

@end
